package com.artogrid.service.impl;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import javax.jms.TextMessage;

import com.artogrid.framework.model.Contact;

public class HornetQListener implements MessageListener {

	@Override
	public void onMessage(Message message) {
		System.out.println("Get Message====================");
		try {
			if (message instanceof TextMessage) {
				TextMessage textMessage = (TextMessage) message;
				System.out.println("Get Message :   "
						+ textMessage.getJMSMessageID() + " "
						+ textMessage.hashCode() + " " + textMessage.getText());
			}else if(message instanceof ObjectMessage){
				 ObjectMessage objectMessage = (ObjectMessage)message;
				 if(objectMessage.getObject() instanceof Contact){
					 Contact contact = (Contact)objectMessage.getObject();
					 System.out.println("===="+contact.getName());
				 }
			}
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}
}
